import { 
  CHANGE_THEME,
  OPEN_LAYOUTS_DIALOG,
  CLOSE_LAYOUTS_DIALOG,
  OPEN_LAYOUTS_SNACKBAR,
  CLOSE_LAYOUTS_SNACKBAR,
  TRIGGER_LAYOUTS_DRAWER,
  WINDOW_WIDTH_CHANGE,
} from '../constants';

import { 
  orange500, 
  orange400,
  orange100,
  cyan500,
  cyan400,
  cyan100,
  teal500,
  teal400,
  teal100,
  pink500,
  pink400,
  pink100,
  indigo500,
  indigo400,
  indigo100,
  lightBlue500,
  lightBlue400,
  lightBlue100,
  red500,
  red400,
  red100,
  blueGrey500,
  blueGrey400,
  blueGrey100
} from 'material-ui/styles/colors';

const initialState = {
  // 页面标题
  title: '首页',
  // 主题
  color100: null,
  color400: null,
  color500: null,
  // 是否为子页面
  isChildrenPage: false,
  // 打开侧边
  openDrawer: true,
  // 样式
  mainOffsetLeft: 224,//224
  mainOffsetTop: 0,
  // 开启tab栏
  openTabs: false,
  // 创建新活动
  openNewActivity: false,
  // 反馈
  openFeedback: false,
  // 小通知
  openSnackbar: false,
  snackbarMessage: '',
  // 是移动端大小窗口
  isSmallViewport: false,
  // userTokenStatus: null,
};

function func(state = initialState, action) {
  switch (action.type) {
    case OPEN_LAYOUTS_DIALOG:
      return Object.assign({}, state, {
        [action.payload]: true
      });
    case CLOSE_LAYOUTS_DIALOG:
      return Object.assign({}, state, {
        [action.payload]: false
      });
    case OPEN_LAYOUTS_SNACKBAR:
      return Object.assign({}, state, {
        openSnackbar: true,
        snackbarMessage: action.payload,
      });
    case CLOSE_LAYOUTS_SNACKBAR:
      return Object.assign({}, state, {
        openSnackbar: false,
        snackbarMessage: '',
      });
    case TRIGGER_LAYOUTS_DRAWER:
      let openDrawer = true;
      let mainOffsetLeft = 224;

      if (state.openDrawer) {
        openDrawer = false;
        mainOffsetLeft = 0;
      }
      return Object.assign({}, state, {
        openDrawer,
        mainOffsetLeft
      });
    case WINDOW_WIDTH_CHANGE:
      return Object.assign({}, state, {
        openDrawer: false,
        mainOffsetLeft: 0,
        isSmallViewport: action.payload,
      });

    case CHANGE_THEME:
      let url = action.payload;
      switch(url)
      {
        case '/i':
        return Object.assign({}, state, {
          title: '首页',
          color500: orange500,
          color400: orange400,
          color100: orange100,
          openTabs: false,
          mainOffsetTop: 0,
          isChildrenPage: false,
        });
        case '/find':
        return Object.assign({}, state, {
          title: '发现',
          color500: teal500,
          color400: teal400,
          color100: teal100,
          openTabs: true,
          mainOffsetTop: 48,
          isChildrenPage: false,
        });
        case '/find/girls':
        return Object.assign({}, state, {
          title: '只看女生',
          color500: pink500,
          color400: pink400,
          color100: pink100,
          openTabs: true,
          mainOffsetTop: 48,
          isChildrenPage: false,
        });
        case '/find/boys':
        return Object.assign({}, state, {
          title: '只看男生',
          color500: indigo500,
          color400: indigo400,
          color100: indigo100,
          openTabs: true,
          mainOffsetTop: 48,
          isChildrenPage: false,
        });
        case '/friends':
        return Object.assign({}, state, {
          title: '好友',
          color500: cyan500,
          color400: cyan400,
          color100: cyan100,
          openTabs: false,
          mainOffsetTop: 0,
          isChildrenPage: false,
        });
        case '/activity/me':
        return Object.assign({}, state, {
          title: '活动',
          color500: lightBlue500,
          color400: lightBlue400,
          color100: lightBlue100,
          openTabs: true,
          mainOffsetTop: 48,
          isChildrenPage: false,
        });
        case '/activity/join':
        return Object.assign({}, state, {
          title: '活动',
          color500: lightBlue500,
          color400: lightBlue400,
          color100: lightBlue100,
          openTabs: true,
          mainOffsetTop: 48,
          isChildrenPage: false,
        });
        case '/notifications':
        return Object.assign({}, state, {
          title: '通知',
          color500: red500,
          color400: red400,
          color100: red100,
          openTabs: false,
          mainOffsetTop: 0,
          isChildrenPage: false,
        });
        default:
        if (url.indexOf('search') !== -1) {
          return Object.assign({}, state, {
            title: '搜索活动',
            color500: orange500,
            color400: orange400,
            color100: orange100,
            openTabs: false,
            mainOffsetTop: 0,
            isChildrenPage: false,
          });
        }else if (url.indexOf('user') !== -1) {
          return Object.assign({}, state, {
            title: '',
            color500: blueGrey500,
            color400: blueGrey400,
            color100: blueGrey100,
            openTabs: false,
            mainOffsetTop: 0,
            openDrawer: false,
            mainOffsetLeft: 0,
            isChildrenPage: true,
          });
        } else if (url.indexOf('activity/show') !== -1) {
          return Object.assign({}, state, {
            title: '',
            color500: orange500,
            color400: orange400,
            color100: orange100,
            openTabs: false,
            mainOffsetTop: 0,
            isChildrenPage: true,
          });
        } else {
          return Object.assign({}, state, {
            title: '',
            color500: orange500,
            color400: orange400,
            color100: orange100,
            openTabs: false,
            mainOffsetTop: 0,
            isChildrenPage: false,
          });
        }
      }
      
    default:
      return state
  }
};

export default func;